//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@infratel.com), 2002-2004
//
// Change extra sections.
//

# include "StdAfx.h"
# include "ExtraSections.h"
# include "UndoRedo.h"
# include "Map.h"

class CSetExtraSectionAction : public CEditAction {
  public:
	CSetExtraSectionAction (section_t & _section, const string_t & _strText) :
		m_section (_section),
		m_strNewText (_strText),
		m_strOldText (_section.strText)
	{}

	virtual void GetName (string_t & _str) const {_str.append ("change extra section");}
	virtual cu_t CanUndo () const {return cuYes;}
	virtual bool Do ();
	virtual void Undo ();
	virtual void Redo () {CSetExtraSectionAction::Do ();}

  private:
	section_t &    m_section;
	string_t const m_strNewText;
	string_t const m_strOldText;
};

bool CSetExtraSectionAction::Do () {
	CCritSec::CLock lock (g_cs);

	m_section.strText = m_strNewText;

	return true;
}

void CSetExtraSectionAction::Undo () {
	CCritSec::CLock lock (g_cs);

	m_section.strText = m_strOldText;
}

///////////////////////////

void SetExtraSection (section_t & _section, const string_t _strText) {
	PerformEditAction (new CSetExtraSectionAction (_section, _strText));
}
